// 金融收案受理费计算
function financeOneAcceptanceFee (amount) {
  if (amount <= 10000) {
    return 1350
  } else if (amount > 10000 && amount <= 100000) {
    const fee = 1350 + (amount - 10000) * 2.5 / 100
    return fee > 2300 ? 2300 : fee
  } else if (amount > 100000 && amount <= 200000) {
    return 2300 + (amount - 100000) * 2 / 100
  } else if (amount > 200000 && amount <= 500000) {
    return 4300 + (amount - 200000) * 1.5 / 100
  } else if (amount > 500000 && amount <= 1000000) {
    return 8800 + (amount - 500000) * 1 / 100
  } else if (amount > 1000000 && amount <= 2000000) {
    return 13800 + (amount - 1000000) * 0.9 / 100
  } else if (amount > 2000000 && amount <= 5000000) {
    return 22800 + (amount - 2000000) * 0.8 / 100
  } else if (amount > 5000000 && amount <= 10000000) {
    return 46800 + (amount - 5000000) * 0.7 / 100
  } else if (amount > 10000000 && amount <= 20000000) {
    return 81800 + (amount - 10000000) * 0.6 / 100
  } else if (amount > 20000000 && amount <= 1500000000) {
    return 141800 + (amount - 20000000) * 0.5 / 100
  } else {
    return 7541800
  }
}

// 金融附录一
export function financeOneFeeCompute (amount) {
  const acceptance = Math.round(financeOneAcceptanceFee(amount))
  return {
    fee_acceptance: acceptance,
    fee_processing: 0,
    fee: acceptance
  }
}

// 金融附录二受理费计算
function financeTwoFeeAcceptace (amount) {
  if (amount <= 1000) {
    return 100
  } else if (amount > 1000 && amount <= 50000) {
    return 100 + (amount - 1000) * 5 / 100
  } else if (amount > 50000 && amount <= 100000) {
    return 2550 + (amount - 50000) * 4 / 100
  } else if (amount > 100000 && amount <= 200000) {
    return 4550 + (amount - 100000) * 3 / 100
  } else if (amount > 200000 && amount <= 500000) {
    return 7550 + (amount - 200000) * 2 / 100
  } else if (amount > 500000 && amount <= 1000000) {
    return 13550 + (amount - 500000) * 1 / 100
  } else if (amount > 1000000 && amount <= 1500000000) {
    return 18550 + (amount - 1000000) * 0.5 / 100
  } else {
    return 7513550
  }
}

// 金融附录二处理费计算
function financeTwoFeeProcessing (amount) {
  if (amount <= 200000) {
    return 1250
  } else if (amount > 200000 && amount <= 500000) {
    return 1250 + (amount - 200000) * 1 / 100
  } else if (amount > 500000 && amount <= 1000000) {
    return 4250 + (amount - 500000) * 0.5 / 100
  } else if (amount > 1000000 && amount <= 10000000) {
    return 6750 + (amount - 1000000) * 0.25 / 100
  } else if (amount > 10000000 && amount <= 1500000000) {
    return 29250 + (amount - 10000000) * 0.15 / 100
  } else {
    return 2264250
  }
}

// 金融附录二收费计算
export function financeTwoFeeCompute (amount) {
  const acceptance = Math.round(financeTwoFeeAcceptace(amount))
  const processing = Math.round(financeTwoFeeProcessing(amount))
  return {
    fee_acceptance: acceptance,
    fee_processing: processing,
    fee: acceptance + processing
  }
}

// 计算特殊收费
export function specialFeeCompute (money) {
  let acceptanceFee = 0
  if (money < 10000) {
    acceptanceFee = 50
  } else if (money >= 10000 && money < 100000) {
    acceptanceFee = money * 0.025 - 200
  } else if (money >= 100000 && money < 200000) {
    acceptanceFee = money * 0.02 + 300
  } else if (money >= 200000 && money < 500000) {
    acceptanceFee = money * 0.015 + 1300
  } else if (money >= 500000 && money < 1000000) {
    acceptanceFee = money * 0.01 + 3800
  } else if (money >= 1000000 && money < 2000000) {
    acceptanceFee = money * 0.009 + 4800
  } else if (money >= 2000000 && money < 5000000) {
    acceptanceFee = money * 0.008 + 6800
  } else if (money >= 5000000 && money < 10000000) {
    acceptanceFee = money * 0.007 + 11800
  } else if (money >= 10000000 && money < 20000000) {
    acceptanceFee = money * 0.006 + 21800
  } else {
    acceptanceFee = money * 0.005 + 41800
  }
  acceptanceFee = Math.round(acceptanceFee)
  return {
    fee_acceptance: acceptanceFee, // 受理费
    fee_processing: 0, // 处理费
    fee: acceptanceFee
  }
}

// 普通受理费计算
function defaultFeeAcceptace (amount) {
  if (amount <= 1000) {
    return 40
  } else if (amount > 1000 && amount <= 50000) {
    return 40 + (amount - 1000) * 0.04
  } else if (amount > 50000 && amount <= 100000) {
    return 2000 + (amount - 50000) * 0.03
  } else if (amount > 100000 && amount <= 200000) {
    return 3500 + (amount - 100000) * 0.02
  } else if (amount > 200000 && amount <= 500000) {
    return 5500 + (amount - 200000) * 0.01
  } else if (amount > 500000 && amount <= 1000000) {
    return 8500 + (amount - 500000) * 0.005
  } else if (amount > 1000000) {
    return 11000 + (amount - 1000000) * 0.0025
  }
}

// 普通处理费计算
function defaultFeeProcessing (acceptFee) {
  const f = 0.2 * acceptFee
  if (f < 200) {
    return 200
  }
  return f
}

// 普通收费计算
export function defaultFeeCompute (amount) {
  const acceptance = Math.round(defaultFeeAcceptace(amount))
  const processing = amount !== 0 ? Math.round(defaultFeeProcessing(acceptance)) : 0
  return {
    fee_acceptance: acceptance,
    fee_processing: processing,
    fee: acceptance + processing
  }
}

// 收费计算
export function computeFee (amount, type = '普通收费') {
  if (type === '金融收费附录一') {
    return financeOneFeeCompute(amount)
  }
  if (type === '金融收费附录二') {
    return financeTwoFeeCompute(amount)
  }
  if (type === '特殊收费') {
    return specialFeeCompute(amount)
  }
  if (type === '普通收费') {
    return defaultFeeCompute(amount)
  }
}
